package QuestionNum_20_1;

import java.security.Key;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class QuestionNum_20_1_hxj {
    public static void main(String[] args) {
        Map<Student,String> map = new HashMap<Student,String>();
        map.put(new Student("姚明",34),"南充");
        map.put(new Student("的刷",32),"成都");
        map.put(new Student("小时",14),"龙泉");

        //1调用map.keySet()方法
        Set<Student> students = map.keySet();
        for (Student student : students) {
            System.out.println(student+map.get(student));
        }
        System.out.println("=========================");
        //2调用map.entrySet()方法----常用
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            System.out.println(entry.getKey()+entry.getValue());
            System.out.println(entry);
        }
        System.out.println("=========================");
        //3迭代器遍历
        Iterator<Map.Entry< Student, String>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<Student, String> entry = iterator.next();
            System.out.println(entry.getKey()+entry.getValue());
        }

        System.out.println("=========================");
        //4遍历map集合中的所有value值（该方法不能遍历操作key值）
        for(Object m:map.values()){
            System.out.println(m);
        }
    }
}
